package com.jinsp.startup_library;

/**
 * Created by luoshuai on 2/25/22
 * <p>
 * 启动任务线程
 */
public class StartupRunnable implements Runnable {

    private final Startup<?> startup;
    private final StartupManager startupManager;

    public StartupRunnable(Startup<?> startup, StartupManager startupManager) {
        this.startup = startup;
        this.startupManager = startupManager;
    }

    @Override
    public void run() {
        startup.startWaiting();     //暂停等待其他任务执行
        Object initResult = startup.init();
        StartupResult<Object> startupResult = new StartupResult<>(initResult);
        StartupResultManager.getInstance().saveStartupInitResult((Class<? extends Startup<?>>) startup.getClass(),
                startupResult);
        //让下一个启动任务继续运行
        startupManager.notifyNextStartupRunning(startup);
    }
}
